package com.guowei.web.util;

import java.math.BigDecimal;

public class DecimalUtil {

    public static String divide(long dividend, long divisor, int scale, int roundingMode) {
        return new BigDecimal(dividend).divide(new BigDecimal(divisor), scale, roundingMode).toString();
    }

    public static String trim0(String decimal) {
        int indexOf = decimal.indexOf(".");
        if (indexOf != -1) {
            for (int i = decimal.length() - 1; i > indexOf; i--) {
                char c = decimal.charAt(i);
                if (c != '0') {
                    return decimal.substring(0, i + 1);
                }
            }
            return decimal.substring(0, indexOf);
        }
        return decimal;
    }
}
